<?php
namespace app\admin\controller;
use \think\Controller;
use \think\Request;
use app\TipMessage;
use think\Model;
class Base extends Controller
{
   
    public function _initialize() 
    {
        $this->getMenu();
    }

    public function test()
    {
        $this->getMenu();
    }

    //是否为post请求
    public function isPost()
    {
        return Request::instance()->isPost();
    }

    // public function success($code = '', $url = NULL, $data = '', $wait = 3, array $header = [])
    // {
    //     $msg    =  $this->getTipMessage($code);
    //     parent::success($msg, $url, $data, $wait, $header);
    // }

    // public function error($code = '', $url = null, $data = '', $wait = 3, array $header = [])
    // {
    //     $msg    =  $this->getTipMessage($code, $url, $data, $wait, $header);
    //     parent::error($msg, $url, $data, $wait, $header);
    // }
    
    /**
     * 获取左侧菜单
     * @author 鬼谷子 <majianwei168@outlook.com>
     * @DateTime 2017-03-03T21:18:29+0800
     * @return   array                   
     */
    protected function getMenu()
    {
      
        $map ['status']     = 1;
        $map ['is_show']    = 1;
        $map ['is_delete']  = 1;
        $field = 'id,title,url,pid';
        $data = db('menu')->field('id,title,url,pid')->where(array('pid' => 0))->where($map)->order('sort DESC')->select();
        foreach ($data as $key => $value) {
            $data [$key]['children'] = db('menu')->field($field)->where($map)->where(array('pid' => $value ['id']))->order('sort DESC')->select();
        }
        // dump($data);
        $this->assign('leftmenu', $data);
    }

    /**
     * 获取消息字符
     * @author 七秒の记忆 <Majw998@gmail.com>
     * @datetime 2017-02-15T16:44:26+0800
     * @param    integer                  $code 消息代号
     * @return   string                         消息
     */
    protected function getTipMessage($code = 0)
    {
        return TipMessage::adminMessage($code);
    }
}